package com.somsoft.handjc.activity.query.xuncha;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.somsoft.handjc.activity.LoginActivity;
import com.somsoft.handjc.activity.MainActivity;
import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.activity.setting.SetIpActivity;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.Utils;
import com.somsoft.handjc.util.XunChaDataUtil;
import com.somsoft.handjc.xuncha.po.BusinessInfo;
import com.somsoft.handjc.xzzf.po.CaseInfo;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
/**
 * 案件信息查询
 * 
 * @author Administrator
 * 
 */
@SuppressWarnings("all")
public class ZhongHeQueryFeedbackActivity extends ListActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setTitle("阶段反馈信息");
		List<Map<String, Object>> listItem = new ArrayList<Map<String, Object>>();
		try {
			listItem = getData(getIntent());
		} catch (Exception e) {
			Toast.makeText(ZhongHeQueryFeedbackActivity.this, "加载数据失败！", Toast.LENGTH_SHORT).show();
		}
			
		SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.xuncha_zhonghe_query_feedback, 
				new String[] { "stageNumber","stageTarget", "stageDate", "stageDays","descs","feedbackTime","finishStatus","feedFiles" },
				new int[] { R.id.stageNumber,R.id.stageTarget, R.id.stageDate, R.id.stageDays,R.id.descs, R.id.feedbackTime, R.id.finishStatus,R.id.feedFiles });
		setListAdapter(listItemAdapter);
		Utils.closeLoading();
	}

	
	private List<Map<String, Object>> getData(Intent it) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if(it!=null){
			String busiId = it.getStringExtra("busiId");
			
			if(busiId != null){
				params.add(new BasicNameValuePair("busiId",busiId));
			}
		}
		
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONArray array = XunChaDataUtil.getFeedback(params);
			Map<String, Object> map = null;
			for(int i = 0; i < array.length(); i++){
				JSONObject obj = array.getJSONObject(i);
				map = new HashMap<String, Object>(); 
				map.put("stageNumber", "阶段序号："+obj.getString("stageNumber"));
				map.put("stageTarget", "阶段目标："+obj.getString("stageTarget"));
				map.put("stageDate", "阶段时间段："+obj.getString("stageDate"));
				map.put("stageDays", "阶段天数："+obj.getString("stageDays"));
				map.put("descs", "反馈内容："+obj.getString("descs").replaceAll("\n", ""));
				map.put("feedbackTime", "反馈时间："+obj.getString("feedbackTime"));
				map.put("finishStatus", "完成情况："+obj.getString("finishStatus"));
				map.put("feedFiles", "上传文件："+obj.getString("feedFiles"));
				list.add(map);
			}
		} catch (Exception e) {
			throw e;
		}
		return list;

	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {			
		menu.add(Menu.NONE, 10, 10, "首页").setIcon(android.R.drawable.ic_menu_compass);
		menu.add(Menu.NONE, 90, 90, "退出").setIcon(android.R.drawable.ic_menu_close_clear_cancel);
		return true;											
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {		// 选中某个菜单项
		Intent it = null;
		switch (item.getItemId()) {								// 判断菜单项ID
		case  10:
			it = new Intent(ZhongHeQueryFeedbackActivity.this,MainActivity.class);
			startActivity(it);
			break;
		case  90:
			MyApplication.getInstance().exit();
			break;
		}
		return false;
	}
}
